import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEMap } from './ipsdemap';
import { IPSDEMapDataSet } from './ipsdemap-data-set';
import { IPSDEDataSet } from '../ds/ipsdedata-set';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEMapDataSetImpl extends PSModelObjectImpl implements IPSDEMapDataSet {
  get codeName(): string {
    return this.M.codeName;
  }

  protected dstpsdedataset: IPSDEDataSet | null = null;

  getDstPSDEDataSet(): IPSDEDataSet | null {
    if (this.dstpsdedataset != null) return this.dstpsdedataset;
    const value = this.M.getDstPSDEDataSet;
    if (value == null) {
      return null;
    }
    const ipsdemap = this.getParentPSModelObject('dataentity.datamap.IPSDEMap') as IPSDEMap;
    if (ipsdemap != null) {
      this.dstpsdedataset = ipsdemap.getDstPSDEMust().findPSDEDataSet(value);
    }
    return this.dstpsdedataset;
  }

  get dstPSDEDataSet(): IPSDEDataSet | null {
    return this.getDstPSDEDataSet();
  }

  getDstPSDEDataSetMust(): IPSDEDataSet {
    const value = this.getDstPSDEDataSet();
    if (value == null) {
      throw new Error('未指定目标实体数据集合');
    }
    return value;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get mapMode(): 'DEFAULT' | 'INNER' {
    return this.M.mapMode || 'DEFAULT';
  }

  get mapParams(): IModel {
    return this.M.mapParams;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected srcpsdedataset: IPSDEDataSet | null = null;

  getSrcPSDEDataSet(): IPSDEDataSet | null {
    if (this.srcpsdedataset != null) return this.srcpsdedataset;
    const value = this.M.getSrcPSDEDataSet;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.srcpsdedataset = ipsdataentity.findPSDEDataSet(value);
    }
    return this.srcpsdedataset;
  }

  get srcPSDEDataSet(): IPSDEDataSet | null {
    return this.getSrcPSDEDataSet();
  }

  getSrcPSDEDataSetMust(): IPSDEDataSet {
    const value = this.getSrcPSDEDataSet();
    if (value == null) {
      throw new Error('未指定源实体数据集合');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSDEMapDataSetImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.datamap.IPSDEMapDataSet') return true;
    return super.instanceof(cls);
  }
}
